<?php
/** @noinspection PhpUnused */
declare(strict_types=1);

namespace app\shop\controller;

use app\shop\exception\FailException;
use app\shop\exception\ParamsErrorException;
use app\shop\logic\OrderEvaluateLogic;
use app\shop\validate\OrderEvaluateValidate;
use think\db\exception\DbException;
use think\helper\Arr;
use think\response\Json;

/**
 * @property OrderEvaluateLogic $logic
 */
class OrderEvaluateController extends BaseController
{
    protected string $validateClassName = OrderEvaluateValidate::class;

    protected array $noNeedLogin = ['list', 'tabs'];

    public function __construct(OrderEvaluateLogic $orderEvaluateLogic)
    {
        $this->logic = $orderEvaluateLogic;

        parent::__construct();
    }

    /**
     * 列表
     * @return Json
     * @throws ParamsErrorException
     */
    public function list(): Json
    {
        $params = $this->getInput();

        $this->validateData($params, 'index');

        $result = $this->logic->list($params);

        return $this->success($result);
    }

    /**
     * 添加
     * @return Json
     * @throws ParamsErrorException
     * @throws FailException|DbException
     */
    public function add(): Json
    {
        $params = $this->postInput(true);

        $this->validateData($params, 'add');

        if (!Arr::get($params, 'order_id') && !Arr::get($params, 'detail_id')) {
            throw new ParamsErrorException('缺少订单参数');
        }

        $result = $this->logic->add($params);

        return $this->success($result);
    }

    public function tabs(): Json
    {
        $params = $this->getInput();

        $result = $this->logic->tabs($params);

        return $this->success($result);
    }
}